<template>
    <div>
      <i-table :columns="columns1" :data="data1"></i-table>
      <Page :total="pageData.total" :current="pageData.current" :page-size="pageData.size"
            show-elevator show-total @on-change="changePage">
      </Page>
    </div>
</template>

<script>
  import {sortPage} from '@/api/blogSortApi';
  import {dealPageData} from "@/utils/myPageUtil";
  import {Button} from "iview";
    export default {
      name: "blogSortAdmin",
      //用于刷新页面
      inject: ['reload'],
      data () {
        return {
          pageData:{
            total:0,
            current:1,
            size:10,
            data:[]
          },
          columns1: [
            {
              title: '分类名称',
              key: 'sortName'
            },
            {
              title: '简介',
              key:"content"
            },
            {
              title: '状态',
              key: 'status',
              render: (h, params) => {
                if (params.row.status == 1) {
                  return h('span', '正常');
                }else {
                  return h('span', '禁用');
                }
              }
            },
            {
              title: '点击数量',
              key: 'clickCount'
            },
            {
              title: '创建时间',
              key: 'createTime',
            },
            {
              title: '修改时间',
              key: 'updateTime',
            },
            {
              title: '操作',
              key: 'action',
              width: 150,
              fixed: 'right',
              align: 'center',
              render: (h, params) => {
                return h("div", [//渲染一个div标签
                  h(
                    Button,
                    {
                      props: {
                        type: "primary",
                        size: "small"
                      },
                      on: {
                        click: () => {
                          //this.editMenuFun(params.row.id);
                        }
                      }
                    },
                    "编辑"
                  ),
                  h(
                    Button,
                    {
                      props: {
                        type: "error",
                        size: "small"
                      },
                      on: {
                        click: () => {
                          //this.remove(params.row.id);
                        }
                      }
                    },
                    "删除"
                  ),
                ]);
              }
            }
          ],
          data1: []
        }
      },
      methods:{
        changePage(index){
          //加载分页数据
          sortPage(index,this.pageData.size).then(res => {
            if(res.data.code == 200){
              //处理分页
              this.pageData = dealPageData(res.data);
              this.data1 = this.pageData.data;
            }
          })
      }
      },
      created(){
          //加载分页数据
        sortPage(this.pageData.current,this.pageData.size).then(res => {
          if(res.data.code == 200){
            //处理分页
            this.pageData = dealPageData(res.data);
            this.data1 = this.pageData.data;
          }
        })
      }

    }
</script>

<style scoped>

</style>
